* ======================================================
* Bergman, Krauss, Thürk: "In for a penny, in for a pound? 
* Evidence that government support parties cannot dissociate 
* themselves from the Prime Minister's party"
*
* The Journal of Politics
*  
* Replication Do File 
* ======================================================

* download and install necessary Stata packages
* Install plottig
net install gr0070.pkg, replace

* Install coefplot
ssc install coefplot, replace

* set working directory for cross-country analysis
clear
cd "..." 
set more off
* open main dataset for cross-country analysis
use "...\Bergman_et_al_JOP_cross_country.dta", clear

*******************************************************
******* Model for Figure 1 in Main Body of Paper ******
*******************************************************
* quietly run main model
* set panel for parties
xtset party_n year
quietly reg d_party_lr c.d_pm_lr##i.govcat c.l_pm_lr##i.govcat if pm!=1, cluster(party_n)
* set scheme for graph
set scheme plotplain
** Left part of figure 1: only support and oppsition parties
quietly margins govcat if govcat==1 | govcat==2, at(d_pm_lr=(-1.5(0.25)1.5)) level(95)
marginsplot, xlabel(-1.5(0.5)1.5, nogrid) ///
    xtitle("Perceived PM Party Shifts") ///
    ylabel( , angle(horizontal) nogrid) ///
    ytitle("Predicted party shifts") ///
    yline(0, lpattern(solid) lcolor(plr2)) ///
    recast(line) ///
    recastci(rline) ///
    plot1opts(lpattern(solid) lcolor(gs10)) /// 
    ci1opts(lpattern(dash) lcolor(gs10)) /// 
    plot2opts(lpattern(solid) lcolor(gs4)) /// 
    ci2opts(lpattern(dash) lcolor(gs4)) /// 
    title("") ///
    name(support, replace)
	
**Right part of figure 1: only junior coalition members and oppsition parties
quietly margins govcat if govcat==1 | govcat==3, at(d_pm_lr=(-1.5(0.25)1.5)) level(95)
marginsplot, xlabel(-1.5(0.5)1.5, nogrid) ///
    xtitle("Perceived PM Party Shifts") ///
    ylabel( , angle(horizontal) nogrid) ///
    ytitle("Predicted party shifts") ///
    yline(0, lpattern(solid) lcolor(plr2)) ///
    recast(line) ///
    recastci(rline) ///
    plot1opts(lpattern(solid) lcolor(gs10)) /// 
    ci1opts(lpattern(dash) lcolor(gs10)) /// 
    plot2opts(lpattern(solid) lcolor(gs4)) /// 
    ci2opts(lpattern(dash) lcolor(gs4)) /// 
    title("") ///
    name(opposition, replace)

**Combine both parts for Figure 1 as in main body of paper
graph combine support opposition, ycommon


*******************************************************
******* Model for Figure 2 in Main Body of Paper ******
*******************************************************
*set working directory for Spanish panel analysis
clear
cd "..." 
set more off
* open second dataset for Spanish panel analysis
use "...\Bergman_et_al_JOP_spanish_panel.dta", clear
* set scheme for graph
set scheme plotplain
*first quietly estimate models (full results in appendix)
quietly reg IUshift UPshift c.interest2 UPposition1 IUposition1 ownshift, cluster(region)
est sto IUUP
quietly reg Csshift c.PSOEshift c.interest2 PSOEposition1 Csposition1 ownshift, cluster(region)
est sto CsPSOE
quietly reg UPshift PSOEshift c.interest2 PSOEposition1 UPposition1 ownshift, cluster(region)
est sto UPPSOE
quietly reg UPshiftDecentral PSOEshiftDecentral c.interest2 PSOEDECposition1 UPDECposition1 ownshiftDecentral, cluster(region)
est sto UPPSOEdec

* Plot the results
coefplot IUUP , bylabel(Electoral alliance (UP-UI)) || CsPSOE , bylabel(Govt-Opp (PSOE-Cs)) || UPPSOE, bylabel(Govt-Support (PSOE-UP))  || UPPSOEdec , bylabel(Govt-Support (PSOE-UP))  ///
keep(*shift*) drop(own*) xline(0) byopts(r(1)) yscale(off) xscale(off) grid(none) ///
subtitle(, size(small))


********************************************************
********* APPENDIX B - CROSS COUNTRY ANALYSES **********
********************************************************
* set working directory for cross-country analysis
clear
cd "..." 
set more off
* open main dataset for cross-country analysis
use "...\Bergman_et_al_JOP_cross_country.dta", clear


*** Replication of Table A.2 in Appendix (Base Models)
xtset party_n year
*Model 1 Appendix: Replication of Bernardi and Adams with additional data for EES 2019
* Basic model (1)
reg d_party_lr c.d_pm_lr##i.govt c.l_pm_lr##i.govt if pm!=1, cluster(party_n)
estimates store base1
*Model 2 Appendix: Replication of Bernardi and Adams with additional data for EES 2019 with country year fixed effects
reg d_party_lr c.d_pm_lr##i.govt c.l_pm_lr##i.govt i.year if pm!=1, cluster(party_n)
estimates store base2

*** Output for Table A2 in Appendix: Move up main outcome variable of interest by hand, Stata will always show interaction effects after individual effects
esttab base1 base2 using "base.rtf", label replace star(* 0.1 ** 0.05 *** 0.01) ar2 se 

*** Replication of Table A.3 in Appendix (Main Models)
xtset party_n year
*Model 3 Appendix: government participation and support party status
reg d_party_lr c.d_pm_lr##i.govcat c.l_pm_lr##i.govcat if pm!=1, cluster(party_n)
*gen gov_sample_red = 1 if e(sample)
estimates store main1
*Model 4 Appendix: government participation and support party status with country year fixed effects
reg d_party_lr c.d_pm_lr##i.govcat c.l_pm_lr##i.govcat i.year if pm!=1, cluster(party_n) 
estimates store main2

*** Output for Table A3 in Appendix: Move up main outcome variable of interest by hand, Stata will always show interaction effects after individual effects
esttab main1 main2 using "main.rtf", label replace star(* 0.1 ** 0.05 *** 0.01) ar2 se 


** Figure A.1 for base model
quietly reg d_party_lr c.d_pm_lr##i.govt c.l_pm_lr##i.govt if pm!=1, cluster(party_n)
quietly margins govt, at(d_pm_lr=(-1.5(0.25)1.5)) 
marginsplot, xlabel(-1.5(0.5)1.5, nogrid) ///
    xtitle("Perceived PM Party Shifts") ///
    ylabel( , angle(horizontal) nogrid) ///
    ytitle("Predicted party shifts") ///
    yline(0, lpattern(solid) lcolor(plr2)) ///
    recast(line) ///
    recastci(rline) ///
    plot1opts(lpattern(solid) lcolor(gs10)) /// 
    ci1opts(lpattern(dash) lcolor(gs10)) /// 
    plot2opts(lpattern(solid) lcolor(gs4)) /// 
    ci2opts(lpattern(dash) lcolor(gs4)) /// 
    title("")
	

*** Figure A.2 for null findings  with opposition pary shifts
**null findings graph: support and opposition
quietly reg d_party_lr c.d_pm_lr##i.govcat c.l_pm_lr##i.govcat if pm!=1, cluster(party_n)
quietly margins govcat if govcat==1 | govcat==2, at(l_pm_lr=(1(0.5)9)) 
marginsplot, xlabel(1(1)9, nogrid) ///
    xtitle("Perceived PM Party Position (t-1)") ///
    ylabel( , angle(horizontal) nogrid) ///
    ytitle("Predicted party shifts") ///
    yline(0, lpattern(solid) lcolor(plr2)) ///
    recast(line) ///
    recastci(rline) ///
    plot1opts(lpattern(solid) lcolor(gs10)) /// 
    ci1opts(lpattern(dash) lcolor(gs10)) /// 
    plot2opts(lpattern(solid) lcolor(gs4)) ///
    ci2opts(lpattern(dash) lcolor(gs4)) /// 
    title("") ///
    name(nullsupport, replace)

** null findings graph: junior and opposition
quietly margins govcat if govcat==1 | govcat==3, at(l_pm_lr=(1(0.5)9)) 
marginsplot, xlabel(1(1)9, nogrid) ///
    xtitle("Perceived PM Party Position (t-1)") ///
    ylabel( , angle(horizontal) nogrid) ///
    ytitle("Predicted party shifts") ///
    yline(0, lpattern(solid) lcolor(plr2)) ///
    recast(line) ///
    recastci(rline) ///
    plot1opts(lpattern(solid) lcolor(gs10)) /// 
    ci1opts(lpattern(dash) lcolor(gs10)) /// 
    plot2opts(lpattern(solid) lcolor(gs4)) ///
    ci2opts(lpattern(dash) lcolor(gs4)) /// 
    title("") ///
    name(nulljunior, replace)

graph combine nullsupport nulljunior, ycommon

*** Summary statistics Table A.4
xtset party_n year
quietly reg d_party_lr c.d_pm_lr##i.govcat c.l_pm_lr##i.govcat if pm!=1, cluster(party_n)

* Generate an indicator variable for non-missing observations
gen in_regression = e(sample)

* Generate summary statistics for the retained sample
sum d_party_lr d_pm_lr c.l_pm_lr  if in_regression
tabulate govcat if in_regression

********************************************************
********* APPENDIX C - SPANISH PANEL ANALYSIS **********
********************************************************
*set working directory for Spanish panel analysis
clear
cd "..." 
set more off
* open second dataset for Spanish panel analysis
use "...\Bergman_et_al_JOP_spanish_panel.dta", clear


*Table A8_1
reg IUshift UPshift c.interest2 UPposition1 IUposition1 ownshift, cluster(region)
est sto IUUP
*Table A8_2
reg Csshift c.PSOEshift c.interest2 PSOEposition1 Csposition1 ownshift, cluster(region)
est sto CsPSOE
*Table A8_3
reg UPshift PSOEshift c.interest2 PSOEposition1 UPposition1 ownshift, cluster(region)
est sto UPPSOE
*Table A7
tabstat * if e(sample) ,col(stat) stat(N mean sd min max)
*Table A8_4 & A9
reg UPshiftDecentral PSOEshiftDecentral c.interest2 PSOEDECposition1 UPDECposition1 ownshiftDecentral, cluster(region)
est sto UPPSOEdec
*Table A10
reg UPshift c.PSOEshift##c.interest2 PSOEposition1 UPposition1 ownshift if UPIU==1, cluster(region)
reg UPshift c.PSOEshift##c.interest2 PSOEposition1 UPposition1 ownshift if UPIU==0, cluster(region)

*Table A6
generate PSOEposition2=PSOEposition1+PSOEshift
mean PSOEposition2
mean PSOEposition1 if e(sample)
generate UPposition2=UPposition1+UPshift
mean UPposition2
mean UPposition1 if e(sample)

*Figure A3
hist UPshift
hist PSOEshift

*Figure A4_1
estimates restore IUUP
margins, at(UPshift=(-10(1)10))
marginsplot, yline(0)

*Figure A4_2
estimates restore CsPSOE
margins, at(PSOEshift=(-10(1)10))
marginsplot, yline(0)

*Figure A4_3
estimates restore UPPSOE
margins, at(PSOEshift=(-10(1)10))
marginsplot, yline(0)

*Figure A4_4
estimates restore UPPSOEdec
margins, at(PSOEshiftDecentral=(-10(1)10))
marginsplot, yline(0)

*Figure A5_1
reg UPshift c.PSOEshift##c.interest2 PSOEposition1 UPposition1 ownshift if UPIU==1, cluster(region)
margins, at(PSOEshift=(-10(1)10) interest2=(0 3))
marginsplot, yline(0) legend(lab(1 "not at all") lab(2 "a lot")) plot1opts(lpattern(solid) lcolor(gs10)) ci1opts(lpattern(dash) lcolor(gs10)) recast(line) recastci(rline) 
*Figure A5_2
reg UPshift c.PSOEshift##c.interest2 PSOEposition1 UPposition1 ownshift if UPIU==0, cluster(region)
margins, at(PSOEshift=(-10(1)10) interest2=(0 3))
marginsplot, yline(0) legend(lab(1 "not at all") lab(2 "a lot")) plot1opts(lpattern(solid) lcolor(gs10)) ci1opts(lpattern(dash) lcolor(gs10)) recast(line) recastci(rline) 


